<template>
    <div style="margin: 20px" />
    <p style="color:red"> {{ message }}</p>
    <el-form :label-position="labelPosition" label-width="100px" :model="form" style="max-width: 460px">
        <el-form-item label="Name">
            <el-input v-model="form.username" />
        </el-form-item>
        <el-form-item label="password">
            <el-input v-model="form.password" password />
        </el-form-item>
        <el-form-item label="Activity form">
            <el-input v-model="form.type" />
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submitForm()">
                login
            </el-button>
            <el-button @click="resetForm()">Reset</el-button>
            <div> <router-link to="/register">register</router-link></div>

        </el-form-item>
    </el-form>
</template>

<script >
import axios from 'axios'
export default {
    data() {
        return {
            form: {
                username: '',
                password: "",
                type: ''
            },
            message: ""
        }
    },

    // function test(params) {
    //     return  params
    // }
    // params=>{ return params }

    methods: {

        submitForm() {
            // form: {
            console.log("login.vue>>>>1111>>>>")
            axios.post("/user/login",
                this.form  //交给mock的登陆逻辑  回调方法 axios
            ).then(res => {
                console.log("login.vue>>>5555555>>>>>" + res)
                console.log(res)
                if (res.data.code == 200) {
                    console.log("login.vue>>>666666>>>>>" + res)
                    alert(res.data.msg)
                    this.$router.push('/main')
                } else {
                    console.log("login.vue>>>666666>>>>>" + res)
                    this.message = res.data.msg
                }
            })

            // if (this.form.name == 'admin' && this.form.password == 'admin') {

            //     this.$router.push('/main')
            // }

        },
        resetForm() { }
    },

}





</script>
